package com.inspur.edp.ai.flow.node;

import com.inspur.edp.ai.flow.metadata.AbsNode;
import com.inspur.edp.ai.flow.spi.NodeCompiler;
import com.inspur.edp.common.expr.ast.ASTContext;
import com.inspur.edp.common.expr.evaluator.EvaluatorService;
import com.inspur.edp.common.expr.evaluator.ExpressEvaluator;
import com.inspur.edp.common.expr.expresses.setvalue.AssignValueExpr;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lizhaorui
 * @date 2025/9/16
 * @description
 */
public class BatchAssignValueNodeCompiler implements NodeCompiler {

    @Override
    public String getKind() {
        return BatchAssignValueNode.KIND;
    }

    @Override
    public Map<String, ExpressEvaluator> compile(ASTContext context, AbsNode absNode) {
        BatchAssignValueNode batchAssignValueNode = (BatchAssignValueNode) absNode;
        Map<String, ExpressEvaluator> needInputMap = new HashMap<>();
        batchAssignValueNode.setExpressEvaluators(new ArrayList<>());
        if (batchAssignValueNode.getExpresses() != null) {
            for (AssignValueExpr expr : batchAssignValueNode.getExpresses()) {
                ExpressEvaluator expressEvaluator = EvaluatorService.build(context, expr);
                batchAssignValueNode.getExpressEvaluators().add(expressEvaluator);
                //处理输入参数的依赖
                EvaluatorService.putDependVars(context, expr,needInputMap);
            }
        }
        return needInputMap;
    }
}